﻿using Fast.ConfigureOptions;
using Fast.Extensions.RabbitMQ;
using Microsoft.Extensions.Configuration;

namespace Fast.Extensions.EventBus.RabbitMQ
{
    /// <summary>
    /// RabbitMQ EventBus配置选项类
    /// </summary>
    [SkipScan, ConfigureOptions(JsonKey = "RabbitMQ:EventBus")]
    public class FastRabbitMqEventBusOptions : IConfigureOptions<FastRabbitMqEventBusOptions>
    {
        /// <summary>
        /// 连接名,表示要连接ConnectionPoll中哪个RabbitMQ连接
        /// </summary>
        public string ConnectionName { get; set; }

        /// <summary>
        /// 交换机名称
        /// </summary>
        public string ExchangeName { get; set; }

        /// <summary>
        /// 发布失败重试次数
        /// </summary>
        public int? PublishFailRetryCount { get; set; }

        /// <summary>
        /// 是否启用死信交换
        /// </summary>
        public bool? EnableDeadLetterExchange { get; set; }

        public void PostConfigure(FastRabbitMqEventBusOptions options, IConfiguration configuration)
        {
            ConnectionName ??= RabbitMqConnections.DefaultConnectionName;
            ExchangeName ??= "fast.default.exchange";
            PublishFailRetryCount ??= 3;
            EnableDeadLetterExchange ??= true;
        }
    }
}